DATEADD

语法

DATEADD ( <日期列>, <偏移量>, <偏移单位> )
参数 属性 描述
日期列 包含日期的列
偏移量 一个整数,
偏移单位 Day,Month,Quarter,Year

返回值

#表 包含单列日期的表

备注

示例

--  DATEADD is a more generic functions.
--  It shifts a period back and forth over time using
--  DAY, MONTH, QUARTER, YEAR
--  This example produces the same result as SAMEPERIODLASTYEAR
EVALUATE
VAR StartDate = DATE ( 2008, 07, 25 )
VAR EndDate =   DATE ( 2008, 07, 31 )
RETURN
    CALCULATETABLE (
        DATEADD ( 'Date'[Date], -1, YEAR ),
        'Date'[Date] >= StartDate &&
        'Date'[Date] <= EndDate
    )
ORDER BY [Date]


   --  DATEADD has a quite complex logic to move months and quarters
--  the right way, handling months with different dates.
EVALUATE
VAR StartDate = DATE ( 2008, 02, 25 )
VAR EndDate =   DATE ( 2008, 02, 29 )
RETURN
    CALCULATETABLE (
        DATEADD ( 'Date'[Date], +1, MONTH ),
        'Date'[Date] >= StartDate &&
        'Date'[Date] <= EndDate
    )
ORDER BY [Date]


 --  This example shows the sales in the current and previous month.
--  It also reports sales in the same month in the previous quarter and year.
DEFINE
    MEASURE Sales[Same period last month] =
        CALCULATE (
            [Sales Amount],
            DATEADD ( 'Date'[Date], -1, MONTH )
        )
    MEASURE Sales[Same period last quarter] =
        CALCULATE (
            [Sales Amount],
            DATEADD ( 'Date'[Date], -1, QUARTER )
        )
    MEASURE Sales[Same period last year] =
        CALCULATE (
            [Sales Amount],
            SAMEPERIODLASTYEAR ( 'Date'[Date] )
        )
EVALUATE
SUMMARIZECOLUMNS (
    'Date'[Calendar Year Month Number],
    'Date'[Calendar Year Month],
    "Sales Amount", [Sales Amount],
    "Same period last month", [Same period last month],
    "Same period last quarter", [Same period last quarter],
    "Same period last year", [Same period last year]
)
ORDER BY [Calendar Year Month Number]

重点文章

相关函数

PARALLELPERIOD